package com.smartens.boit.welcome;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.smartens.boit.MainActivity;
import com.smartens.boit.R;
import com.smartens.boit.bean.LoginBean;
import com.smartens.boit.login.LoginActivity;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/**
 * @author songtt
 */
public class WelcomeActivity extends AppCompatActivity {
    private static ScheduledExecutorService scheduledExecutorService;
    private static TimerTask timerTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);


        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                getUserInfo();
            }
        };
        timer.schedule(timerTask, 2000);
    }

    public void getUserInfo(){
        SharedPreferences sharedPreferences= getSharedPreferences("data", Context.MODE_PRIVATE);
        String userName=sharedPreferences.getString("userName","");

        if(userName.length()>0){
            Intent intent1 = new Intent(WelcomeActivity.this, MainActivity.class);
            startActivity(intent1);
            WelcomeActivity.this.finish();
        }else {
            Intent intent1 = new Intent(WelcomeActivity.this, LoginActivity.class);
            startActivity(intent1);
            WelcomeActivity.this.finish();
        }
    }
}